package jsyf.oa.web.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.system.User2RoleFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/12/7 0007.
 */
@Api(value = "用户兼职接口", description = "用户兼职接口")
@Controller
@RequestMapping("/user2Role")
public class User2RoleController {

    @Resource
    private User2RoleFacade user2RoleFacade;

    @RequestMapping(value = "/config.json", method = RequestMethod.POST)
    public void config(HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonParam = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);
        String userId = jsonParam.getString("userId");
        String roleIds = jsonParam.getString("roleIds");
        Boolean result = user2RoleFacade.config(userId, roleIds);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(String.valueOf(result)));
    }
    /**
     * 查询用户职位
     *
     * @param response
     * @param jsonData
     */
    @RequestMapping(value = "/getRolesByUserId.json", method = RequestMethod.POST)
    public void getRolesByUserId(HttpServletResponse response, @RequestBody String jsonData) {

        List<JSONObject> resultList = this.user2RoleFacade.getRolesByUserId(jsonData);
        String result = "";
        result = BaseUtils.succsessArrRespond(resultList);
        ResponseUtils.putJsonResponse(response, result);
    }

}
